package com.zhou.demo.interfaceclass;

import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.zhou.demo.callback.LaunchCallback;
import com.zhou.demo.url.ZhihuUrl;

import org.xutils.http.RequestParams;

import java.io.IOException;

/**
 * Created by 11065 on 2016/8/11.
 */
public class LauchConnect implements LaunchInterface {

    @Override
    public void getLaunchImage(final LaunchCallback launchCallback) {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(ZhihuUrl.FIRSTPAGEIMAGE)
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                String code = e.getMessage();
                launchCallback.OnLaunchFail(code);
            }

            @Override
            public void onResponse(Response response) throws IOException {
                launchCallback.OnLaunchSuccess(response.body().string());
            }
        });
    }
}
interface LaunchInterface{
    void getLaunchImage(LaunchCallback launchCallback);
}
